package nl.infodation.emr.utility;

import java.util.StringTokenizer;


public final class StringUtil {
	
	private StringUtil(){
	}
	
	static public boolean isEmptyOrBlank(final String str) {
		return str == null || str.trim().isEmpty();
	}
	
	static public String getValueWithoutNull(String value) {
		if (null == value) {
			return "";
		}
		return value;
	}
	
	static public String splitString(String str)
	{
		if (null == str) {
			return "";
		}
		String result = str;
		if(str.contains("(")) {
			result = str.split("\\(")[0];
		}
		 
		return result;
	}
	
	static public String correctDoubleFieldFormat(String doubleValue) {
		Double value = DoubleUtil.parseDouble(doubleValue);
		if (null == value) {
			return "";
		}
		
		String doubleResult = String.format("%.3f", value);
		
		return doubleResult;
	}
	
	static public String correctIntegerFieldFormat(String integerValue) {
		Integer value = IntegerUtil.parseInteger(integerValue);
		if (null == value) {
			return "";
		}
		
		String doubleResult = String.format("%d", value);
		
		return doubleResult;
	}
	
	static public boolean isCodeVersion(final String versionCode) {
		final StringTokenizer stringTokenizer = new StringTokenizer(versionCode);
		boolean check = Boolean.FALSE;

		while (stringTokenizer.hasMoreTokens()) {
			final String element = stringTokenizer.nextToken(";");
			if (element.equals(Constants.VERSION_CODE)) {
				check = Boolean.TRUE;
				break;
			}
		}
		return check;
	}
	
}
